<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 方式一 reduce+includes
    function unique(arr) {
      return arr.reduce((pre,cur)=>{
        return pre.includes(cur)?pre:[...pre,cur]
      },[])
    }
    // 方式二 利用filter和indexOf
    function unique2(arr) {
      return arr.filter((item,index)=>{
        return arr.indexOf(item)==index
      })
    }
    // 方式三 filter和map
    function unique3(arr) {
      let map = new Map()
      return arr.filter(item=>!map.has(item)&&map.set(item))
    }
    let arr = [1,2,32,4,2,2,3,2,5,2,3,5]
    console.log(unique3(arr));
    console.log(unique2(arr));
    console.log(unique(arr));
  </script>
</body>
</html>